package com.vnaloha.common.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.stereotype.Repository;
import com.vnaloha.common.model.Category;
import com.vnaloha.util.CustomHibernateDaoSupport;

@Repository
public class CategoryDAOImpl extends CustomHibernateDaoSupport implements CategoryDAO{

	@SuppressWarnings("unchecked")
	@Override
	public List<Category> list() {
		List<Category> list = null;
		try {
			list = getHibernateTemplate().find(" from Category order by id desc");
		} catch (HibernateException e) {
			logger.error("Error when get list Category " + e, e);
		}
		return list;
	}

	@Override
	public Category get(int id) {
		Category category = (Category) getHibernateTemplate().get(Category.class, id);

		if (null != category) {
			return category;
		}
		logger.error("Error when get category by id " + id);
		return null;
	}

}
